<?php
session_start();
if(!isset($_SESSION['obuserid'])){
	header("location: login.php");
}
require('../config.ini.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="../css/admin-style.css">
<link rel="stylesheet" type="text/css" href="../css/blitzer/jquery-ui-1.8.custom.css" />
</head>

<body>
	<div id="page-wrap">
        <div id="page-content">
        	<div id="content-colleft">
            	<div id="colleft-wrap">
                <h1 class="header-sys"><a style="color:#a8a8a8; text-decoration:none;" href="index.php">ผู้ดูแลระบบบ้านรักสุขภาพ</a></h1>
                <p><a class="sys-menu" id="edit-profile">แก้ไขข้อมูลส่วนตัว</a> <a onClick="parent.location='logout.php'" class="sys-menu">ออกจากระบบ</a></p>
                
            	<div id="colleft-menu">
                	<div style="text-align:right;">
                    <div id="accordion">
                    	<?php if($_SESSION["obusertype"]=="2") {  ?>
                    	<h3><a href="#">จัดการอาหาร</a></h3>
                            <div>
                                <p><a href="#" onclick="loadUrl('food.php')">เรียกดูอาหาร</a></p>
                                <p><a href="#" onclick="openFormadd('form-addfood')">เพิ่มอาหาร</a></p>
                            </div>
                         <h3><a href="#">จัดการประเภทอาหาร</a></h3>
                            <div>
                                <p><a href="#" onclick="loadUrl('foodtype.php')">เรียกดูประเภทอาหาร</a></p>
                                <p><a href="#" onclick="openFormadd('form-addfoodtype')">เพิ่มประเภทอาหาร</a></p>
                            </div>
                          <h3><a href="#" disease>จัดการโรค</a></h3>
                            <div>
                                <p><a href="#" onclick="loadUrl('disease.php')">เรียกดูโรค</a></p>
                                <p><a href="#" onclick="openFormadd('form-adddisease')">เพิ่มโรค</a></p>
                            </div>
                            <h3><a href="#">จัดการข่าว</a></h3>
                            <div>
                                <p><a href="#" onclick="loadUrl('notice.php')">เรียกดูข่าว</a></p>
                                <p><a href="#" id="a-addnews">เพิ่มข่าว</a></p>
                                <p><a href="#" onclick="loadUrl('noticetype.php')">เรียกดูประเภทข่าว</a></p>
                                <p><a href="#" onclick="openFormadd('form-addnoticetype')">เพิ่มประเภทข่าว</a></p>
                            </div>
                            <h3><a href="#">จัดการผลิตภัณฑ์</a></h3>
                            <div>
                                <p><a href="#" onclick="loadUrl('product.php')">เรียกดูผลิตภัณฑ์</a></p>
                                <p><a href="#" onclick="openFormadd('form-addproduct')">เพิ่มผลิตภัณฑ์</a></p>
                            </div>
                            <?php } ?>
                            <?php if($_SESSION["obusertype"]=="3"){  ?>
                            <h3><a href="#">จัดการผู้ใช้ระบบ</a></h3>
                            <div>
                                <p><a href="#" onclick="loadUrl('user.php')">เรียกดูผู้ใช้ระบบ</a></p>
                                <p><a href="#" onclick="openFormadd('form-addprofile')">เพิ่มผู้ใช้ระบบ</a></p>
                            </div>
							<?php } ?>
                            <?php if($_SESSION["obusertype"]=="4") { ?>
                            <h3><a href="#">รายงาน</a></h3>
                            <div>
                                <p><a href="reportuser.php" target="_blank">รายงานผู้ใช้ระบบ</a></p>
                                <p><a href="#" onclick="loadUrl('userreport.php')">รายงานน้ำหนักสมาชิก</a></p>
                            </div>
                            <?php } ?>
					</div>
                </div>
                </div>
                </div>
            </div>
            <div id="content-colright">
            	<div id="colright-wrap">
            		<h1 class="header-sys">ยินดีต้อนรับ</h1>
                    <?php
                    	$sql = "SELECT userdata.username, userdata.usersname FROM userdata WHERE userdata.userid = '$_SESSION[obuserid]' AND userdata.userstatus = '1'";
						$result = mysql_query($sql);
						$row = mysql_fetch_array($result);
						mysql_free_result($result);
					?>
                    <p>คุณ <?php echo $row['0']."  ".$row['1']; ?></p>
                    <div id="div-result" style="margin:20px 0;"></div>
                 </div>
            </div>
            <div class="clear"></div>
        </div>
        <div id="page-footer">
        </div> 
	</div>
    <!--- form edit profile --->
    <div id="form-editprofile" class="formJquery" title="แก้ไขข้อมูลส่วนตัว">
        <form>
            <fieldset class ="fieldset">
            <label for="efname">ชื่อ</label><input type="text" name="efname" id="efname" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="elname">นามสกุล</label><input type="text" name="elname" id="elname" value=""  class="text ui-widget-content ui-corner-all w1"/>
            <label for="euserpassword">รหัสผ่าน</label><input type="password" name="euserpassword" id="euserpassword" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="eaddress">ที่อยู่</label><textarea name="eaddress" id="eaddress" class="text ui-widget-content ui-corner-all w1"></textarea>
            <label for="eemail">อีเมลล์</label><input type="text" name="eemail" id="eemail" value=""  class="text ui-widget-content ui-corner-all w1"/>
            <label for="etel">โทรศัพท์</label><input type="text" name="etel" id="etel" value=""  class="text ui-widget-content ui-corner-all w1"/>
            <label for="emobile">โทรศัพท์เคลื่อนที่</label><input type="text" name="emobile" id="emobile" value=""  class="text ui-widget-content ui-corner-all w1"/>
            <input type="hidden" name="action" value="editprofile" />
            <input type="hidden" name="euserid" value="<?php echo $_SESSION['obuserid']; ?>" />
            <p>
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="button" id="btn-save-profile" value="บันทึกข้อมูล" />
            </p>
            </fieldset>
        </form>
    </div>
    <!-- end form edit profile --->
    
    <!-- start form add food --->
    <?php
		$sql = "SELECT categoryid, categoryname FROM foodcategory where status = '1' ORDER BY categoryid DESC";
		$result = mysql_query($sql);
		$optfoodcat = "";
		while ($row=mysql_fetch_array($result)){
			$optfoodcat .= "<option value='$row[0]'>$row[1]</option>";
		}
		mysql_free_result($result);
		?>
    <div id="form-addfood" class="formJquery" title="เพิ่มอาหาร">
        <form>
            <fieldset class ="fieldset">
            	<div style="width:900px;">
            	<label class="label-food">ชื่ออาหาร</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="foodname" id="foodname" />
                <label class="label-food">ประเภทอาหาร</label><select class="text ui-widget-content ui-corner-all input-food" name="foodcategoryid" id="foodcategoryid"><?php echo $optfoodcat; ?></select>
                <label class="label-food">foodunit</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="foodunit" id="foodunit" />
                <label class="label-food">foodcc</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="foodcc" id="foodcc" />
                <label class="label-food">totalcallory</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="totalcallory" id="totalcallory" />
                <label class="label-food">fatcallory</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="fatcallory" id="fatcallory" />
                <label class="label-food">totalfat</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="totalfat" id="totalfat" />
                <label class="label-food">saturatedfat</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="saturatedfat" id="saturatedfat" />
                <label class="label-food">cholestoral</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="cholestoral" id="cholestoral" />
                <label class="label-food">protein</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="protein" id="protein" />
                <label class="label-food">carbohydrate</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="carbohydrate" id="carbohydrate" />
                <label class="label-food">dietaryfiber</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="dietaryfiber" id="dietaryfiber" />
                <label class="label-food">vitamina</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="vitamina" id="vitamina" />
                <label class="label-food">thiamin</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="thiamin" id="thiamin" />
                <label class="label-food">riboflavin</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="riboflavin" id="riboflavin" />
                <label class="label-food">niacin</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="niacin" id="niacin" />
                <label class="label-food">vitaminb6</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="vitaminb6" id="vitaminb6" />
                <label class="label-food">folicacid</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="folicacid" id="folicacid" />
                <label class="label-food">biotin</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="biotin" id="biotin" />
                <label class="label-food">panlothenicacid</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="panlothenicacid" id="panlothenicacid" />
                <label class="label-food">vitaminb12</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="vitaminb12" id="vitaminb12" />
                <label class="label-food">vitaminc</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="vitaminc" id="vitaminc" />
                <label class="label-food">vitamind</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="vitamind" id="vitamind" />
                <label class="label-food">vitamine</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="vitamine" id="vitamine" />
                <label class="label-food">vitamink</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="vitamink" id="vitamink" />
                <label class="label-food">calcium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="calcium" id="calcium" />
                <label class="label-food">phosphorus</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="phosphorus" id="phosphorus" />
                <label class="label-food">iron</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="iron" id="iron" />
                <label class="label-food">iodine</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="iodine" id="iodine" />
                <label class="label-food">magnesium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="magnesium" id="magnesium" />
                <label class="label-food">zinc</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="zinc" id="zinc" />
                <label class="label-food">copper</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="copper" id="copper" />
                <label class="label-food">potassium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="potassium" id="potassium" />
                <label class="label-food">sodium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="sodium" id="sodium" />
                <label class="label-food">manganese</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="manganese" id="manganese" />
                <label class="label-food">selenium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="selenium" id="selenium" />
                <label class="label-food">fluoride</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="fluoride" id="fluoride" />
                <label class="label-food">molybdenum</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="molybdenum" id="molybdenum" />
                <label class="label-food">chromium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="chromium" id="chromium" />
                <label class="label-food">chloride</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="chloride" id="chloride" />
                <div class="clear"></div>
                <p>
                <input type="hidden" name="action" value="addfood" />
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="button" id="btn-save-food" value="บันทึกข้อมูล" />
                </p>
                </div>
             </fieldset>   
		</form>
	</div>
    <!-- end form add food --->
    
    <!-- start form edit food --->
    <div id="form-editfood" class="formJquery" title="แก้ไขอาหาร">
        <form>
            <fieldset class ="fieldset">
            	<div style="width:900px;">
            	<label class="label-food">ชื่ออาหาร</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="efoodname" id="efoodname" />
                <label class="label-food">ประเภทอาหาร</label><select class="text ui-widget-content ui-corner-all input-food" name="efoodcategoryid" id="efoodcategoryid"><?php echo $optfoodcat; ?></select>
                <label class="label-food">foodunit</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="efoodunit" id="efoodunit" />
                <label class="label-food">foodcc</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="efoodcc" id="efoodcc" />
                <label class="label-food">totalcallory</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="etotalcallory" id="etotalcallory" />
                <label class="label-food">fatcallory</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="efatcallory" id="efatcallory" />
                <label class="label-food">totalfat</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="etotalfat" id="etotalfat" />
                <label class="label-food">saturatedfat</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="esaturatedfat" id="esaturatedfat" />
                <label class="label-food">cholestoral</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="echolestoral" id="echolestoral" />
                <label class="label-food">protein</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="eprotein" id="eprotein" />
                <label class="label-food">carbohydrate</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="ecarbohydrate" id="ecarbohydrate" />
                <label class="label-food">dietaryfiber</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="edietaryfiber" id="edietaryfiber" />
                <label class="label-food">vitamina</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="evitamina" id="evitamina" />
                <label class="label-food">thiamin</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="ethiamin" id="ethiamin" />
                <label class="label-food">riboflavin</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="eriboflavin" id="eriboflavin" />
                <label class="label-food">niacin</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="eniacin" id="eniacin" />
                <label class="label-food">vitaminb6</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="evitaminb6" id="evitaminb6" />
                <label class="label-food">folicacid</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="efolicacid" id="efolicacid" />
                <label class="label-food">biotin</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="ebiotin" id="ebiotin" />
                <label class="label-food">panlothenicacid</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="epanlothenicacid" id="epanlothenicacid" />
                <label class="label-food">vitaminb12</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="evitaminb12" id="evitaminb12" />
                <label class="label-food">vitaminc</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="evitaminc" id="evitaminc" />
                <label class="label-food">vitamind</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="evitamind" id="evitamind" />
                <label class="label-food">vitamine</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="evitamine" id="evitamine" />
                <label class="label-food">vitamink</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="evitamink" id="evitamink" />
                <label class="label-food">calcium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="ecalcium" id="ecalcium" />
                <label class="label-food">phosphorus</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="ephosphorus" id="ephosphorus" />
                <label class="label-food">iron</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="eiron" id="eiron" />
                <label class="label-food">iodine</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="eiodine" id="eiodine" />
                <label class="label-food">magnesium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="emagnesium" id="emagnesium" />
                <label class="label-food">zinc</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="ezinc" id="ezinc" />
                <label class="label-food">copper</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="ecopper" id="ecopper" />
                <label class="label-food">potassium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="epotassium" id="epotassium" />
                <label class="label-food">sodium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="esodium" id="esodium" />
                <label class="label-food">manganese</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="emanganese" id="emanganese" />
                <label class="label-food">selenium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="eselenium" id="eselenium" />
                <label class="label-food">fluoride</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="efluoride" id="efluoride" />
                <label class="label-food">molybdenum</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="emolybdenum" id="emolybdenum" />
                <label class="label-food">chromium</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="echromium" id="echromium" />
                <label class="label-food">chloride</label><input type="text" class="text ui-widget-content ui-corner-all input-food" name="echloride" id="echloride" />
                <div class="clear"></div>
                <p>
                <input type="hidden" name="efoodid" id="efoodid"/>
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="button" id="btn-edit-food" value="บันทึกข้อมูล" />
                </p>
                </div>
             </fieldset>   
		</form>
	</div>
    <!-- end form edit food --->
    
    <!-- form form add foodtype --->
    <div id="form-addfoodtype" class="formJquery" title="เพิ่มประเภทอาหาร">
        <form>
            <fieldset class ="fieldset">
            <label for="foodtypename">ประเภทอาหาร</label><input type="text" name="foodtypename" id="foodtypename" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="foodtypedes">รายละเอียดเพิ่มเติม</label><textarea name="foodtypedes" id="foodtypedes" class="text ui-widget-content ui-corner-all w1"></textarea>  
            <p>
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="button" id="btn-save-foodtype" value="บันทึกข้อมูล" />
            </p>
            </fieldset>
        </form>
    </div>
    <!-- end form add foodtype --->
    
    <!-- form form edit foodtype --->
    <div id="form-editfoodtype" class="formJquery" title="แก้ไขประเภทอาหาร">
        <form>
            <fieldset class ="fieldset">
            <label for="foodtypename">ประเภทอาหาร</label><input type="text" name="editfoodtypename" id="editfoodtypename" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="foodtypedes">รายละเอียดเพิ่มเติม</label><textarea name="editfoodtypedes" id="editfoodtypedes" class="text ui-widget-content ui-corner-all w1"></textarea>  
            <p>
            	<input type="hidden" name="foodtypeid" value="" id="foodtypeid" />
            	<input type="hidden" name="action" value="updatefoodtype"  />
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="button" id="btn-edit-foodtype" value="บันทึกข้อมูล" />
            </p>
            </fieldset>
        </form>
    </div>
    <!-- end form edit foodtype --->
    
    <!-- form form add disease --->
    <div id="form-adddisease" class="formJquery" title="เพิ่มโรค">
        <form>
            <fieldset class ="fieldset">
            <label for="diseasename">ชื่อโรค</label><input type="text" name="diseasename" id="diseasename" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="diseasedes">รายละเอียดเพิ่มเติม</label><textarea name="diseasedes" id="diseasedes" class="text ui-widget-content ui-corner-all w1"></textarea>  
            <p>
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="button" id="btn-save-disease" value="บันทึกข้อมูล" />
            </p>
            </fieldset>
        </form>
    </div>
    <!-- end form add disease --->
    
    <!-- form form edit disease --->
    <div id="form-editdisease" class="formJquery" title="แก้ไขโรค">
        <form>
            <fieldset class ="fieldset">
            <label for="editdiseasename">ชื่อโรค</label><input type="text" name="editdiseasename" id="editdiseasename" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="editdiseasedes">รายละเอียดเพิ่มเติม</label><textarea name="editdiseasedes" id="editdiseasedes" style="height:200px;" class="text ui-widget-content ui-corner-all w1"></textarea>  
            <p>
            	<input type="hidden" name="diseaseid" value="" id="diseaseid" />
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="button" id="btn-edit-disease" value="บันทึกข้อมูล" />
            </p>
            </fieldset>
        </form>
    </div>
    <!-- end form edit disease --->
    
    <!-- form form add noticetype --->
    <div id="form-addnoticetype" class="formJquery" title="เพิ่มประเภทข่าว">
        <form>
            <fieldset class ="fieldset">
            <label for="noticetypename">ชื่อประเภทข่าว</label><input type="text" name="noticetypename" id="noticetypename" value="" class="text ui-widget-content ui-corner-all w1" /> 
            <p>
            	<input type="hidden" name="action" value="addnoticetype" />
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="button" id="btn-save-noticetype" value="บันทึกข้อมูล" />
            </p>
            </fieldset>
        </form>
    </div>
    <!-- end form add noticetype --->
    
    <!-- form form edit noticetype --->
    <div id="form-editnoticetype" class="formJquery" title="แก้ไขประเภทข่าว">
        <form>
            <fieldset class ="fieldset">
            <label for="enoticetypename">ชื่อประเภทข่าว</label><input type="text" name="enoticetypename" id="enoticetypename" value="" class="text ui-widget-content ui-corner-all w1" /> 
            <p>
            	<input type="hidden" name="noticetypeid" id="noticetypeid" />
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="button" id="btn-edit-noticetype" value="บันทึกข้อมูล" />
            </p>
            </fieldset>
        </form>
    </div>
    <!-- end form edit noticetype --->
    
    <!-- form add news --->
    <div id="form-addnews" class="formJquery" title="เพิ่มข่าว">
        <form action="action.php" enctype="multipart/form-data" method="post" target="uploadtarget">
            <fieldset class ="fieldset">
            <label for="noticehead">หัวข้อข่าว</label><input type="text" name="noticehead" id="noticehead" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="noticecontent">รายละเอียด</label><textarea name="noticecontent" id="noticecontent" class="text ui-widget-content ui-corner-all w1"></textarea>
            <label for="add-noticetype">ประเภทข่าว</label><select  name="noticetypeid" id="add-noticetype" value=""  class="text ui-widget-content ui-corner-all w1"></select>
			<label for="addnewspic">รูปประกอบ</label><input type="file" name="addnewspic" id="addnewspic" class="text ui-widget-content ui-corner-all w1"/>
            <p>
            	<input type="hidden" name="action" value="addnews" />
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="submit" id="btn-save-news" value="บันทึกข้อมูล" />
            </p>
            </fieldset>
        </form>
    </div>
    
    <div id="form-editnews" class="formJquery" title="แก้ไขข่าว">
        <form action="action.php" enctype="multipart/form-data" method="post" target="uploadtarget">
            <fieldset class ="fieldset">
            <label for="enoticehead">หัวข้อข่าว</label><input type="text" name="enoticehead" id="enoticehead" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="enoticecontent">รายละเอียด</label><textarea name="enoticecontent" id="enoticecontent" class="text ui-widget-content ui-corner-all w1"></textarea>
            <label for="eadd-noticetype">ประเภทข่าว</label><select  name="enoticetypeid" id="eadd-noticetype" value=""  class="text ui-widget-content ui-corner-all w1"></select>
			<label for="eaddnewspic">รูปประกอบ</label><input type="file" name="eaddnewspic" id="eaddnewspic" class="text ui-widget-content ui-corner-all w1"/>
            <p>
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="submit" id="btn-edit-news" value="บันทึกข้อมูล" />
            </p>
            </fieldset>
        </form>
    </div>
    
    <div id="form-addproduct" class="formJquery" title="เพิ่มผลิตภัณฑ์">
        <form action="action.php" enctype="multipart/form-data" method="post" target="uploadtarget">
            <fieldset class ="fieldset">
            <label for="productname">ชื่อผลิตภัณฑ์</label><input type="text" name="productname" id="productname" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="productdetail">รายละเอียด</label><textarea name="productdetail" id="productdetail" class="text ui-widget-content ui-corner-all w1"></textarea>
			<label for="addproductpic">รูปประกอบ</label><input type="file" name="addproductpic" id="addproductpic" class="text ui-widget-content ui-corner-all w1"/>
            <p>
            	<input type="hidden" name="action" value="addproduct" />
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="submit" id="btn-save-product" value="บันทึกข้อมูล" />
            </p>
            </fieldset>
        </form>
    </div>
    
    <div id="form-editproduct" class="formJquery" title="แก้ไขผลิตภัณฑ์">
        <form action="action.php" enctype="multipart/form-data" method="post" target="uploadtarget">
            <fieldset class ="fieldset">
            <label for="editproductname">ชื่อผลิตภัณฑ์</label><input type="text" name="editproductname" id="editproductname" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="editproductdetail">รายละเอียด</label><textarea name="editproductdetail" id="editproductdetail" class="text ui-widget-content ui-corner-all w1"></textarea>
			<label for="editproductpic">รูปประกอบ</label><input type="file" name="editproductpic" id="editproductpic" class="text ui-widget-content ui-corner-all w1"/>
            <p>
            	<input type="hidden" name="productid" id="productid"  value="" />
                <input type="button" class="btn-cancle" value="ยกเลิก" />
                <input type="submit" id="btn-edit-product" value="บันทึกข้อมูล" />
            </p>
            </fieldset>
        </form>
    </div>
    
     
    <iframe id="uploadtarget" name="uploadtarget" src="" style="border:0px;height:0px;width:0px;line-height:1px;display:none;">
    	
    </iframe>
    <!-- end form add news --->
    
    <!-- form edit profile --->
    <div id="form-viewprofile" class="formJquery" title="ดูข้อมูลสมาชิก">
        <form>
            <fieldset class ="fieldset">
            <label for="vfname">ชื่อ</label><input type="text" name="vfname" id="vfname" disabled="disabled" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="vlname">นามสกุล</label><input type="text" name="vlname" id="vlname" disabled="disabled" value=""  class="text ui-widget-content ui-corner-all w1"/>
            <label for="vsex">เพศ</label><input type="text" name="vsex" id="vsex" disabled="disabled"  value=""  class="text ui-widget-content ui-corner-all w1"/>
            <label for="vaddress">ที่อยู่</label><textarea name="vaddress" id="vaddress" disabled="disabled" class="text ui-widget-content ui-corner-all w1"></textarea>
            <label for="vemail">อีเมลล์</label><input type="text" name="vemail" id="vemail"  disabled="disabled" value=""  class="text ui-widget-content ui-corner-all w1"/>
            <label for="vtel">โทรศัพท์</label><input type="text" name="vtel" id="vtel" value=""  disabled="disabled"  class="text ui-widget-content ui-corner-all w1"/>
            <label for="vmobile">โทรศัพท์เคลื่อนที่</label><input type="text" name="vmobile" id="vmobile" value=""  disabled="disabled"   class="text ui-widget-content ui-corner-all w1"/>
            <p>
            <input type="button" class="btn-cancle" value="ยกเลิก" />
            </p>
            </fieldset>
        </form>
    </div>
    <!-- end form edit profile --->
    
    <!-- form add profile --->
    <div id="form-addprofile" class="formJquery" title="เพิ่มสมาชิก">
        <form>
            <fieldset class ="fieldset">
            <label for="nuserid">ชื่อบัญชี</label><input type="text" name="nuserid" id="nuserid" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="nfname">ชื่อ</label><input type="text" name="nfname" id="nfname" value="" class="text ui-widget-content ui-corner-all w1" />
            <label for="nlname">นามสกุล</label><input type="text" name="nlname" id="nlname" value=""  class="text ui-widget-content ui-corner-all w1"/>
            <label>เพศ</label>
            <p style="margin-bottom:10px;">
            <label><input type="radio" name="nsex" value="0" /> หญิง </label><label><input type="radio" name="nsex" value="1" /> ชาย </label>
            </p>
            <label for="ntype">ประเภทผู้ใช้</label>
            <select id="ntype" name="ntype" class="text ui-widget-content ui-corner-all w1">
            	<option value="-" selected="selected"> - กรุณาเลือก - </option>
            	<option value="2">พนักงาน</option>
                <option value="3">ผู้ดูแลระบบ</option>
                <option value="4">ผู้บริหาร</option>
            </select>
            <label for="naddress">ที่อยู่</label><textarea name="naddress" id="naddress" class="text ui-widget-content ui-corner-all w1"></textarea>
            <label for="nemail">อีเมลล์</label><input type="text" name="nemail" id="nemail"   value=""  class="text ui-widget-content ui-corner-all w1"/>
            <label for="ntel">โทรศัพท์</label><input type="text" name="ntel" id="ntel" value=""   class="text ui-widget-content ui-corner-all w1"/>
            <label for="nmobile">โทรศัพท์เคลื่อนที่</label><input type="text" name="nmobile" id="nmobile" value=""  class="text ui-widget-content ui-corner-all w1"/>
            <input type="hidden" name="action" value="adduserprofile" />
            <p>
            <input type="button" id="btn-save-newuser" value="บันทึกข้อมูล" />
            <input type="button" class="btn-cancle" value="ยกเลิก" />
            </p>
            </fieldset>
        </form>
    </div>
    <!-- end form edit profile --->
    
    <script src="../js/jquery-1.4.2.min.js"></script>
    <script src="../js/jquery-ui-1.8.custom.min.js"></script>
    <script>
    	$(function(){
		
			$("#accordion").accordion({
				collapsible: true,
				active: false,
				autoHeight: false
				
			});
			
			$("#accordion > *").css("font-size","75%");
			
			$("#form-editprofile").dialog({
				autoOpen: false,
                resizable: false,
				height: 430,
				width: 250,
				modal: true
			});
			
			$('#edit-profile').click(function() {
				$.getJSON("action.php", {action:"listprofile"},function(json){
					$("#efname").val(json.euserprofile[0].username);
					$("#elname").val(json.euserprofile[0].usersname);
					$("#euserpassword").val("");
					$("#eaddress").val(json.euserprofile[0].address);
					$("#eemail").val(json.euserprofile[0].email);
					$("#emobile").val(json.euserprofile[0].mobile);
					$("#etel").val(json.euserprofile[0].tel);
					$('#form-editprofile').dialog('open');
				});
			});
			
			$("#btn-save-profile").click(function(){
				var fields = $("#form-editprofile>form").serializeArray();
				$.ajax({
				   type: "POST",
				   url: "action.php?action?editprofile",
				   data: fields,
				   success: function(msg){
					 	alert( "แก้ไขข้อมูลสำเร็จ");
						$('#form-editprofile').dialog('close');
				   }
				 });
			});
			
			
			
			$("#form-addfood").dialog({
				autoOpen: false,
                resizable: false,
				height: 515,
				width: 932,
				modal: true
			});
			
			$("#form-editfood").dialog({
				autoOpen: false,
                resizable: false,
				height: 515,
				width: 932,
				modal: true
			});
			
			$("#form-addfoodtype").dialog({
				autoOpen: false,
                resizable: false,
				height: 200,
				width: 300,
				modal: true
			});
			
			$("#form-editfoodtype").dialog({
				autoOpen: false,
                resizable: false,
				height: 200,
				width: 300,
				modal: true
			});
			
			$("#form-adddisease").dialog({
				autoOpen: false,
                resizable: false,
				height: 200,
				width: 300,
				modal: true
			});
			
			$("#form-editdisease").dialog({
				autoOpen: false,
                resizable: false,
				height: 350,
				width: 300,
				modal: true
			});
			
			$("#form-addnoticetype").dialog({
				autoOpen: false,
                resizable: false,
				height: 130,
				width: 300,
				modal: true
			});
			
			$("#form-editnoticetype").dialog({
				autoOpen: false,
                resizable: false,
				height: 130,
				width: 300,
				modal: true
			});
			
			$("#form-addnews").dialog({
				autoOpen: false,
                resizable: false,
				height: 290,
				width: 300,
				modal: true
			});
			
			$("#form-editnews").dialog({
				autoOpen: false,
                resizable: false,
				height: 290,
				width: 300,
				modal: true
			});
			
			$("#form-addproduct").dialog({
				autoOpen: false,
                resizable: false,
				height: 240,
				width: 300,
				modal: true
			});
			
			
			$("#form-editproduct").dialog({
				autoOpen: false,
                resizable: false,
				height: 240,
				width: 300,
				modal: true
			});
			
			$("#form-viewprofile").dialog({
				autoOpen: false,
                resizable: false,
				height: 410,
				width: 300,
				modal: true
			});
			
			$("#form-addprofile").dialog({
				autoOpen: false,
                resizable: false,
				height: 490,
				width: 300,
				modal: true
			});
			
			$("#a-addnews").click(function(){
			$("input.text,textarea").val("");
				$.get("action.php?action=listnoticetype" ,function(data){
					$("#add-noticetype").html(data);
					$('#form-addnews').dialog('open');
				});
			});
			
			$('.btn-cancle').click(function(){
				$("div[id^='form']").dialog('close');
				clearinput();
			});
			
		});
		
		function clearinput(){
			 $("input.text,textarea").val("");
		}
		
		function loadUrl(fileUrl){
			$("#div-result").load(fileUrl);
		}
		
		function openFormadd(formname){
			clearinput();
			if(formname=="form-addprofile"){ $("#ntype").val("-") }
			$("#"+formname).dialog('open');
		}
		
		$("#btn-save-news").click(function(){
			//var serfield = $("#form-addnews>form").serializeArray();
			function newscallback(){
				alert("เพิ่มข้อมูลสำเร็จ");
				$("#form-addnews").dialog("close");
				loadUrl("notice.php");
			}
			setTimeout(newscallback,500);
		});
		
		$("#btn-save-product").click(function(){
			//var serfield = $("#form-addnews>form").serializeArray();
			function productcallback(){
				alert("เพิ่มข้อมูลสำเร็จ");
				$("#form-addproduct").dialog("close");
				loadUrl("product.php");
			}
			setTimeout(productcallback,1000);
		});
		
		$("#btn-save-noticetype").click(function(){
			var fields = $("#form-addnoticetype>form").serializeArray();
			$.post("action.php",{fields:fields,action:"addnoticetype"},function(data){
				alert("เพิ่มข้อมูลสำเร็จ");
				$("#form-addnoticetype").dialog('close');
				clearinput();
			});
		});
		
		$("#btn-save-food").click(function(){
			var fields = $("#form-addfood>form").serializeArray();
			$.post("action.php",{fields:fields,action:"addfood"},function(data){
				alert("เพิ่มข้อมูลสำเร็จ");
				$("#form-addfood").dialog('close');
				clearinput();
			});
		});
		
		$("#btn-save-foodtype").click(function(){
			var fields = $("#form-addfoodtype>form").serializeArray();
			$.post("action.php",{fields:fields,action:"addfoodtype"},function(data){
				alert("เพิ่มข้อมูลสำเร็จ");
				$("#form-addfoodtype").dialog('close');
				clearinput();
			});
		});
		
		$("#btn-save-disease").click(function(){
			var fields = $("#form-adddisease>form").serializeArray();
			$.post("action.php",{fields:fields,action:"adddisease"},function(data){
				alert("เพิ่มข้อมูลสำเร็จ");
				$("#form-adddisease").dialog('close');
				clearinput();
			});
		});
		
		$("#btn-save-newuser").click(function(){
			var fields = $("#form-addprofile>form").serializeArray();
			$.post("action.php",fields,function(data){
				alert("เพิ่มข้อมูลสำเร็จ");
				$("#form-addprofile").dialog('close');
				clearinput();
			});
		});
		
		function deleteitem(itemdel,itemid,cbload){
			if(confirm("ยืนยันการลบข้อมูล")==true){
				$.post("action.php",{action:itemdel,id:itemid},function(data){
					alert("ลบข้อมูลสำเร็จ");
					loadUrl(cbload);
				});
			}
		}
		
		function listfood(id){
			$.getJSON("action.php", {action:"listfood",id:id},function(json){
				$("#efoodname").val(json.efood[0].foodname);
				$("#efoodcategoryid > option[value='"+json.efood[0].foodcategoryid+"']").attr("selected",true);
				$("#efoodunit").val(json.efood[0].foodunit);
				$("#efoodcc").val(json.efood[0].foodcc);
				$("#etotalcallory").val(json.efood[0].totalcallory);
				$("#efatcallory").val(json.efood[0].fatcallory);
				$("#etotalfat").val(json.efood[0].totalfat);
				$("#esaturatedfat").val(json.efood[0].saturatedfat);
				$("#echolestoral").val(json.efood[0].cholestoral);
				$("#eprotein").val(json.efood[0].protein);
				$("#ecarbohydrate").val(json.efood[0].carbohydrate);
				$("#edietaryfiber").val(json.efood[0].dietaryfiber);
				$("#evitamina").val(json.efood[0].vitamina);
				$("#ethiamin").val(json.efood[0].thiamin);
				$("#eriboflavin").val(json.efood[0].riboflavin);
				$("#eniacin").val(json.efood[0].niacin);
				$("#evitaminb6").val(json.efood[0].vitaminb6);
				$("#efolicacid").val(json.efood[0].folicacid);
				$("#ebiotin").val(json.efood[0].biotin);
				$("#epanlothenicacid").val(json.efood[0].panlothenicacid);
				$("#evitaminb12").val(json.efood[0].vitaminb12);
				$("#evitaminc").val(json.efood[0].vitaminc);
				$("#evitamind").val(json.efood[0].vitamind);
				$("#evitamine").val(json.efood[0].vitamine);
				$("#evitamink").val(json.efood[0].vitamink);
				$("#ecalcium").val(json.efood[0].calcium);
				$("#ephosphorus").val(json.efood[0].phosphorus);
				$("#eiron").val(json.efood[0].iron);
				$("#eiodine").val(json.efood[0].iodine);
				$("#emagnesium").val(json.efood[0].magnesium);
				$("#ezinc").val(json.efood[0].zinc);
				$("#ecopper").val(json.efood[0].copper);
				$("#epotassium").val(json.efood[0].potassium);
				$("#esodium").val(json.efood[0].sodium);
				$("#emanganese").val(json.efood[0].manganese);
				$("#eselenium").val(json.efood[0].selenium);
				$("#efluoride").val(json.efood[0].fluoride);
				$("#emolybdenum").val(json.efood[0].molybdenum);
				$("#echromium").val(json.efood[0].chromium);
				$("#echloride").val(json.efood[0].chloride);
				$("#efoodid").val(json.efood[0].foodid);
				$('#form-editfood').dialog('open');
			});
		}
		
		function listfoodtype(id){
			$.getJSON("action.php", {action:"listfoodtype",id:id},function(json){
				$("#editfoodtypename").val(json.efoodtype[0].categoryname);
				$("#editfoodtypedes").val(json.efoodtype[0].description);
				$("#foodtypeid").val(json.efoodtype[0].categoryid);
				$('#form-editfoodtype').dialog('open');
			});
		}
		
		function listdisease(id){
			$.getJSON("action.php", {action:"listdisease",id:id},function(json){
				$("#editdiseasename").val(json.edisease[0].diseasename);
				$("#editdiseasedes").val(json.edisease[0].description);
				$("#diseaseid").val(json.edisease[0].diseaseid);
				$('#form-editdisease').dialog('open');
			});
		}
		
		function listnoticetype(id){
			$.getJSON("action.php", {action:"listeditnoticetype",id:id},function(json){
				$("#enoticetypename").val(json.enoticetype[0].noticetypename);
				$("#noticetypeid").val(json.enoticetype[0].noticetypeid);
				$('#form-editnoticetype').dialog('open');
			});
		}
			
		function listproduct(id){
			$.getJSON("action.php", {action:"listeditproduct",id:id},function(json){
				$("#editproductname").val(json.eproduct[0].productname);
				$("#editproductdetail").val(json.eproduct[0].productdetail);
				/*if(json.eproduct[0].productimage!=""){
					$('#form-editproduct').append("<img src='../productimages/"+json.eproduct[0].productimage+"' />");
				}*/
				$("#productid").val(json.eproduct[0].productid);
				$('#form-editproduct').dialog('open');
			});
		}
		
		function listnotice(id){
			$.getJSON("action.php", {action:"listnotice",id:id},function(json){
				$("#editproductname").val(json.eproduct[0].productname);
				$("#editproductdetail").val(json.eproduct[0].productdetail);
				/*if(json.eproduct[0].productimage!=""){
					$('#form-editproduct').append("<img src='../productimages/"+json.eproduct[0].productimage+"' />");
				}*/
				$("#productid").val(json.eproduct[0].productid);
				$('#form-editproduct').dialog('open');
			});
		}
		
		function listuser(id){
			var vsex;
			$("#form-viewprofile > input,#form-viewprofile > textarea").val('');
			$.getJSON("action.php",{ action:"listuser",id:id },function(json){
				if(json.vuser[0].sex == "1"){ vsex = "ชาย"; }else{ vsex = "หญิง"; }
				$("#vfname").val(json.vuser[0].username);
				$("#vlname").val(json.vuser[0].usersname);
				$("#vaddress").val(json.vuser[0].address);
				$("#vemail").val(json.vuser[0].email);
				$("#vtel").val(json.vuser[0].tel);
				$("#vsex").val(vsex);
				$("#vmobile").val(json.vuser[0].mobile);
				$('#form-viewprofile').dialog('open');
			});
		}
		
		$("#btn-edit-foodtype").click(function(){
			var fields = $("#form-editfoodtype>form").serializeArray();
			$.post("action.php",{action:"updatefoodtype",fields:fields},function(data){
				alert("แก้ไขข้อมูลสำเร็จ");
				$('#form-editfoodtype').dialog('close');
				loadUrl("foodtype.php");
			});
		});
		
		$("#btn-edit-disease").click(function(){
			var fields = $("#form-editdisease>form").serializeArray();
			$.post("action.php",{action:"updatedisease",fields:fields},function(data){
				alert("แก้ไขข้อมูลสำเร็จ");
				$('#form-editdisease').dialog('close');
				loadUrl("disease.php");
			});
		});
		
		$("#btn-edit-food").click(function(){
				var fields = $("#form-editfood>form").serializeArray();
				$.post("action.php",{action:"updatefood",fields:fields},function(data){
					alert("แก้ไขข้อมูลสำเร็จ");
					$('#form-editfood').dialog('close');
					loadUrl("food.php");
			});
		});
		
		$("#btn-edit-noticetype").click(function(){
				var fields = $("#form-editnoticetype>form").serializeArray();
				$.post("action.php",{action:"updatenoticetype",fields:fields},function(data){
					alert("แก้ไขข้อมูลสำเร็จ");
					$('#form-editnoticetype').dialog('close');
					loadUrl("noticetype.php");
			});
		});
		
		$("#btn-edit-news").click(function(){
			
		});
    </script>
</body>
</html>                        